package com.wus.system.controller;

import com.wus.common.core.domain.base.Result;
import com.wus.common.core.domain.user.AccountInfo;
import com.wus.system.request.LoginUserReq;
import com.wus.system.request.PageRequest;
import com.wus.system.request.SysUserRegisterReq;
import com.wus.system.request.SysUserPageReq;
import com.wus.common.core.domain.page.PageResultDTO;
import com.wus.system.service.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: API测试
 * @Author: wus
 * @Date: 2024/12/8 23:39
 */
@Tag(name = "用户管理")
@Validated
@RequiredArgsConstructor
@RequestMapping("/system/user")
@RestController
public class SysUserController {

    private final Logger logger = LoggerFactory.getLogger(SysUserController.class);

    private final ISysUserService userService;

    @Operation(summary = "用户登录-不对外提供，feign之间调用的，可不提供接口文档")
    @PostMapping("/login")
    public Result<AccountInfo> login(@Validated @RequestBody LoginUserReq req) {
        AccountInfo result = userService.login(req);
        return Result.ok(result);
    }

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public Result<Boolean> register(@Validated @RequestBody SysUserRegisterReq req) {
        Boolean result = userService.register(req);
        return Result.ok(result);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/page")
    public Result<PageResultDTO> page(@Validated @RequestBody PageRequest req) {
        PageResultDTO result = userService.page(req);
        return Result.ok(result);
    }

    @Operation(summary = "自定义分页查询")
    @PostMapping("/customPage")
    public Result<PageResultDTO> page2(@Validated @RequestBody SysUserPageReq req) {
        PageResultDTO result = userService.customPage(req);
        return Result.ok(result);
    }

    @Operation(summary = "测试接口")
    @GetMapping("/test")
    public Result<Boolean> test() {
        return Result.ok(true);
    }
}
